package com.kingint.web.sys.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.kingint.common.unitedresult.K;
import com.kingint.mbg.dto.BackQueryParam;
import com.kingint.mbg.sys.entity.UmsMember;
import com.kingint.web.sys.service.MemberBackService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @描述：会员表控制类
 * @作者: wxh
 * @日期: 2020-12-10
 */
@RestController
@RequestMapping("/member")
@Api(value = "MemberBackController", description = "后台用户控制层")
@CrossOrigin
public class MemberBackController {

    @Resource
    private MemberBackService memberBackService;

    @ApiOperation(value = "添加用户信息")
    @PostMapping(value = "/addMemberInfo")
    public Object addMemberInfo(@RequestBody UmsMember member) {
        Integer integer = memberBackService.insertMemberInfo(member);
        if(integer>0){
            return K.ok().data(integer);
        }
        return K.error();
    }

    @ApiOperation(value = "修改用户信息")
    @PostMapping(value = "/updateMemberInfo")
    public Object updateMemberInfo(@RequestBody UmsMember member) {
        Integer integer = memberBackService.updateMemberInfo(member);
        if(integer>0){
            return K.ok().data(integer);
        }
        return K.error();
    }

    @ApiOperation(value = "删除用户信息")
    @GetMapping(value = "/deleteMemberInfo/{id}")
    public Object deleteMemberInfo(@PathVariable("id") Long id) {
        Integer integer = memberBackService.deleteMemberInfo(id);
        if(integer>0){
            return K.ok().data(integer);
        }
        return K.ok().data(null);
    }
    @ApiOperation(value = "获取用户信息列表")
    @GetMapping(value = "/getMemberList")
    public Object getMemberList(BackQueryParam queryParam,
                                @RequestParam("pageNum") Integer pageNum,
                                @RequestParam("pageSize") Integer pageSize) {
        IPage<UmsMember> allMemberList = memberBackService.getAllMemberList(queryParam, pageNum, pageSize);
        return K.ok().data(allMemberList);
    }

    @ApiOperation(value = "获取对应的用户的详情")
    @GetMapping(value = "/getMemberInfo/{id}")
    public Object getMemberInfo(@PathVariable("id") Long id) {
        UmsMember member= memberBackService.getMemberInfo(id);
        return K.ok().data(member);
    }
}
